# -*- coding: utf-8 -*-
from scripts import forms
from flask import Flask, redirect, url_for, render_template, request, session
import json
import sys
import os
import pprint
app = Flask(__name__)
app.secret_key = os.urandom(12)  # Generic key for dev purposes only

@app.route("/", methods=['GET', 'POST'])
def Payg():
    form = forms.PayGIntegration()
    requestBody = ''
    responseData =''
    responseDataUpdate =''
    orderKeyId = ''
    if request.method == 'POST':
        print("PaygOrderCreate")
        try:
            # responseData=form.orderCreate(request.form)
            result = form.orderCreate(request.form)
            responseData = result["responseData"]
            requestBody = result["requestBody"]
            orderKeyId = responseData.get("OrderKeyId", "")
            
        except Exception as e:
            print(e)
    return render_template('payg.html', form=form,responseData=responseData,responseDataUpdate=responseDataUpdate,orderKeyId=orderKeyId, requestBody=requestBody)
    
# @app.route("/orderupdate", methods=['GET', 'POST'])    
# def PaygOrderUpdate():
#     form = forms.PayGIntegration()
#     responseData =''
#     if request.method == 'POST':
#         print("PaygOrderUpdate")
#         try:
#            responseData=form.orderUpdate(request.form)
#            #form_v.reset()
#         except Exception as e:
#             print(e)
#     return render_template('orderupdate.html', form=form,responseData=responseData)
    
@app.route("/orderdetail", methods=['GET', 'POST'])    
def PaygOrderDetail():
    form = forms.PayGIntegration()
    requestBody = ''
    responseData = ''
    if request.method == 'POST':
        print("PaygOrderDetail")
        try:
        #    responseData=form.orderDetail(request.form)
            result=form.orderDetail(request.form)
            responseData = result["responseData"]
            requestBody = result["requestBody"]
           #form_v.reset()
        except Exception as e:
            print(e)
    return render_template('orderdetail.html', form=form,responseData=responseData, requestBody=requestBody)
    
# ======== Main ============================================================== #
if __name__ == "__main__":
    app.run(debug=True,host="127.0.0.1",port=8000)
